package cn.pzhu.controller.admin;

import cn.pzhu.controller.BaseController;
import cn.pzhu.model.Role;
import cn.pzhu.services.admin.CollegeServices;
import cn.pzhu.services.admin.RoleServices;

import java.util.List;

/**
 * Created by dongp on 2016/4/25.
 */
public class CollegeController extends BaseController {

    private CollegeServices collegeServices = new CollegeServices();

    public void index() {
        render("college.jsp");
    }

//    public void ajaxQuery() {
//        List<Role> roles = collegeServices.ajaxQuery();
//        renderJson(roles);
//    }

    public void ajaxQueryPage() {
        String pageNumber = getPara("pageNumber");
        String pageSize = getPara("pageSize");
        String search = getPara("search","");
        List atrrs = collegeServices.ajaxQueryPage(pageNumber, pageSize, search);
        renderJson(atrrs);
    }

    public void ajaxUpdate() {
        int id = getParaToInt("collegesID",0);
        String name = getPara("name");
        Integer gain = getParaToInt("gain", 0);
        Integer experts = getParaToInt("experts", 0);
        String orgAttr = getPara("orgAttr");
        String researchArea = getPara("researchArea");

        boolean result = collegeServices.ajaxUpdate(id, name, gain, experts, orgAttr, researchArea);
        if(result) {
            setAttr("msg","success");// 该返回的成功信息前台暂时没用
        }else {
            setAttr("msg","failue");
        }

        render("college.jsp");
    }

    public void ajaxAdd() {
        String name = getPara("name");
        Integer gain = getParaToInt("gain", 0);
        Integer experts = getParaToInt("experts",0);
        String orgAttr = getPara("orgAttr");
        String researchArea = getPara("researchArea");

        boolean result = collegeServices.ajaxAdd(name, gain, experts, orgAttr, researchArea);
        render("college.jsp");
    }

    public void ajaxDel() {
        String id = getPara("collegesID");
        boolean result = collegeServices.ajaxDel(id);

        render("college.jsp");
    }

}
